import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:local_coffee/request/routers.dart';

class RqtUser {
  
  final Dio _dio;

  RqtUser(
    this._dio
  );

  /// 注册, 可用作登录
  /// ```
  /// @param {String} code 验证码
  /// @param {String} email 邮箱
  /// @param {String} pwd 密码
  /// @param {bool} autoLogin true / false 是否在注册后自动完成登录【对于之前已注册的用户，自动完成登录】
  /// @param {String} city 城市
  /// @param {String} nick 昵称
  /// @param {String} province 省份
  /// ```
  Future<Response> register({
    @required String code,
    @required String email,
    @required String pwd,
    bool autoLogin = true,
    String city,
    String nick,
    String province
  }) {
    if (nick == null) {
      nick = email.substring(0, email.indexOf('@'));
    }
    return _dio.post(
      Routers.userEmailRegister,
      queryParameters: {
        'code': code,
        'email': email,
        'pwd': pwd,
        'autoLogin': autoLogin,
        'nick': nick,
        'province': province
      }
    );
  }

  /// 获取用户详情
  Future<Response> detail() {
    return _dio.post(Routers.userDetail);
  }

  /// 查看用户资产
  /// ```
  /// @param {String} token
  /// ```
  Future<Response> amount({
    @required String token
  }) {
    return _dio.post(Routers.userAmount);
  }
}